<?php

namespace App\Services\Article;

use App\Services\Article\Article\ArticleLogic;
use App\Services\Article\EnterpriseArticle\EnterpriseArticleLogic;

/**
 * 文章服务层
 * Class ApiArticle
 * @package App\Services\Article
 */
class ApiArticle
{
//--------------------------------企业站前台开始------------------------------------------

    /**
     * 指定分类下的文章列表
     */
    public function articleList($data)
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }

        $data = init_array($data,['cid'=>""]);
        ValidateArticle::checkValidate($data,['cid']);
        return (new EnterpriseArticleLogic())->articleList($data);
    }

    /**
     * 所有文章列表
     */
    public function allList()
    {
        return (new EnterpriseArticleLogic())->allList();
    }

    /**
     * 指定分类下的文章详情
     */
    public function assignInfo($data)
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        $data = init_array($data,['cid'=>" "]);
        ValidateArticle::checkValidate($data,['cid']);

        return (new EnterpriseArticleLogic())->assignInfo($data);
    }

    /**
     * 文章详情
     */
    public function articleInfo($data)
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        $data = init_array($data,['id'=>" "]);
        ValidateArticle::checkValidate($data,['id']);

        return (new EnterpriseArticleLogic())->articleInfo($data);
    }
//--------------------------------企业站前台结束------------------------------------------


    /**
     * 添加文章分类
     */
    public function add($data)
    {
        ValidateArticle::checkValidate($data, ["classify_id", "title", "content", "top", "belong_to", 'img_url']);

        return (new ArticleLogic())->add($data);
    }

    /**
     * 文章编辑
     */
    public function edit($data)
    {
        ValidateArticle::checkValidate($data, ['id', 'classify_id', 'title', 'content', 'top', 'belong_to', 'img_url']);

        return (new ArticleLogic())->edit($data);
    }

    /**
     * 删除某篇文章
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function del($data)
    {
        ValidateArticle::checkValidate($data, ['id']);
        return (new ArticleLogic())->del($data);
    }

    /**
     * 文章列表
     */
    public function list($data)
    {
        ValidateArticle::checkValidate($data, ['status']);

        return (new ArticleLogic())->list($data);
    }

    /**
     * 文章详情
     */
    public function info($data)
    {
        ValidateArticle::checkValidate($data, ['id']);

        return (new ArticleLogic())->info($data);
    }

    /**
     * 智慧头条下的文章分类和文章列表
     */
    public function witList($data)
    {
        ValidateArticle::checkValidate($data, ['pid']);

        return (new ArticleLogic())->witList($data);
    }

}
